package com.marcowu.study.spb.tracing.manager;

import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Component
public class SampleManager {

  private static Logger s_logger = LoggerFactory.getLogger(SampleManager.class);

  private Tracer tracer = GlobalTracer.get();


  public String getSample2(Span span) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    if (attributes != null) {
      HttpServletRequest request = attributes.getRequest();
      s_logger.info("URL : " + request.getRequestURL().toString());
      s_logger.info("HTTP_METHOD : " + request.getMethod());
    }
    span.log("svc : SampleManager.getSample2");
    return "1";
  }
}
